/**
 * 
 */
package de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.feature_types;
import java.util.HashSet;
import java.util.Set;
import de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.FeatureType;
/**
 * 
 * @author Christoph Teichmann
 * created Jun 3, 2014 3:36:43 PM
 * @version 0.1
 */
public abstract class GenericFeatureGenerator implements FeatureType
{
	/**
	 * @param pairs
	 */
	public GenericFeatureGenerator(String[][] pairs, String def)
	{
		this.pairs = pairs;
		this.def = def;
		for(String[] pair : pairs)
		{options.add(pair[1]);}
		options.add(def);
	}
	/**
	 * 
	 */
	private final String[][] pairs;
	/**
	 * 
	 */
	private final String def;
	/**
	 * 
	 */
	private final Set<String> options = new HashSet<>();
	/* (non-Javadoc)
	 * @see de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.FeatureType#getFeatName(java.lang.String)
	 */
	@Override
	public String getFeatName(String s)
	{
		String ret = this.def;
		for(String[] pair : pairs)
		{
			if(s.matches(pair[0]))
			{
				ret = pair[1];
				break;
			}
		}
		return ret;
	}
	/* (non-Javadoc)
	 * @see de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.FeatureType#updateWeight(java.lang.String, boolean, double)
	 */
	@Override
	public double updateWeight(String s, boolean first, double d)
	{return first ? 1.0 : d+1.0;}
	/* (non-Javadoc)
	 * @see de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.FeatureType#getFeatureOptions()
	 */
	@Override
	public Iterable<String> getFeatureOptions()
	{return this.options;}
	/* (non-Javadoc)
	 * @see de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.datacreation.FeatureType#getType()
	 */
	@Override
	public String getType()
	{return "multinomial";}
}